home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / net / writenews2.lha / WriteNews2.www next >
Text File  |  1995-09-18  |  12KB  |  424 lines

  1. /***********************************************************************
  2. * WriteNews2                                                           *
  3. *                                                                      *
  4. * $VER: WriteNews2.3                                                   *
  5. *                                                                      *
  6. * When this script is added to Amiga Mosaic's Macro list,              *
  7. * it allows you to followup or post Newsitems to the news              *
  8. * group you are currently browsing in Amiga Mosaic, or email the       *
  9. * author of the news you are reading.                                  *
  10. *                                                                      *
  11. * Requires:                                                            *
  12. *     Amiga Mosaic 1.2 or higher (tested with 2.0AS225 version)      *
  13. *     NNTPPost & SMTP from INetUtils (AS225 or Amitcp versions)      *
  14. *     Rexxreqtools. Also useful if your editor won't open on         *
  15. *       a defined public screen is Pubutils2 [aminet:utils/wb]         *
  16. *                                                                      *
  17. * Original script by  Gary Gallagher                                   *
  18. * Modified by John Blyth to allow for editor switches                  *
  19. * to insert { send / edit / list / abort } choice before exiting       *
  20. * clean up parsing & extraction of entries, refs and sendmail function *
  21. ***********************************************************************/
  22.  
  23. OPTIONS RESULTS
  24.  
  25. /* TRACE R */
  26. /* Edit the following sections to set it up for your system            */
  27. /* check that you have set the required variables for                  */
  28. /* email address, editor, editor switches, realname, .sig' file        */
  29.  
  30. /**********************************************************************/
  31. /*  START OF SETTINGS SECTION  */
  32.  
  33.   REALNAME = 'Your real name' 
  34. /*           ^^^^^^^^^^^^^^  put your real name here that you would     * 
  35. *                            like to use in any greetings              */
  36.  
  37.   FROM = 'yourname@yourhost' 
  38. /*       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  put your e-mail address here */
  39.  
  40.   USEWB = ''
  41. /*         ^^^   SET TO yes to use workbench as the editor/multiview    *
  42. * screen, otherwise leave blank '' to use mosaic's pubscreen (which     *
  43. * could be workbench anyway)                                            *
  44. * This will be useful If your editor can not open on a public           *
  45. * screen.                                                              */
  46.  
  47.   GREETING = 'On '||DATE()||' '||realname||' wrote:'||'0a'x
  48. /*           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^               *
  49. *  your opening line  for posting news....                            *
  50. *  you might like to change this to a blank line eg greeting = '0a'x    *
  51. *  if you don't like this one... feel free to change it                */
  52.  
  53.   SIGFILE = 'uulib:.signature'
  54. /*          ^^^^^^^^^^^^^^^^  put your sigfile location here            *
  55. *  if you have multiple users on the machine you may be able to use an  *
  56. *  $USER environmental variable, eg uulib:$USER.signature              */
  57.  
  58.  
  59.   POSTMAIL = 'INET:c/SMTPpost -S'
  60.   POSTNEWS = 'INET:c/NNTPpost'
  61. /* Set both of these commands to the news & mailposting options you     *
  62. *  require (see the INETutils manual)  make sure you get your path to   *
  63. *  these utilities correct if you have not placed them in the default   *
  64. *  locations. and any other settings required                           *
  65. ************************************************************************/
  66. /* WE NOW NEED TO GET INFO ABOUT THE SCREEN AMOSAIC IS RUNNING ON      */
  67.  
  68. 'info screen'
  69. SCREENNAME = result
  70. SCREENNAME = Compress(SCREENNAME,'½╗')
  71. if (upper(SCREENNAME) = 'DEFAULT')|(UPPER(USEWB) = 'YES') then
  72. SCREENNAME = 'Workbench'
  73. screentag = "rt_pubscrname = "||SCREENNAME
  74.  
  75. /************************************************************************
  76. * WE CAN NOW COMPLETE OUR SETTINGS                                      */
  77.  
  78.   EDITOR = 'C:Ed' 
  79. /*         ^^^^^^ put your editor here                                  */
  80.  
  81.   EDITORFLAGS = 'window con:0/110/-1/380/Edit_News/screen'||SCREENNAME
  82. /*               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    *
  83. *  put any required editor flags here, eg startup macros or "-sticky"   *
  84. *  commands to prevent your editor detaching from the originating shell *
  85. *  These are editor flags for ed, to make it open on mosaic's pubscreen *
  86. *  you'll need to adjust this line for the editor of your choice        *
  87. ************************************************************************/
  88.  
  89. /* OK let's begin ............ */
  90.  
  91.  
  92. if ~show(l, "rexxsupport.library") then
  93.     if ~addlib("rexxsupport.library", 0, -30) then
  94.    exit
  95.  
  96. if ~show(l, "rexxreqtools.library") then
  97.     if ~addlib("rexxreqtools.library", 0, -30) then
  98.    exit
  99.  
  100. if upper(usewb) = 'YES' then 'screen back'
  101.  
  102. /* write or followup a message */
  103.  
  104. from = from||' ('||realname||')'
  105.  
  106. call rtezrequest('Do you want to post a new message, follow one up or mail the author?',,
  107.     '_Post|_Follow up|_Mail|_Cancel',,'rtez_defaultresponse = 2 ' screentag)
  108.  
  109.  
  110. mail = 0
  111. select
  112.     when rtresult == 1 then
  113.          call WRITE
  114.     when rtresult == 2 then
  115.          call FOLLOW_UP
  116.     when rtresult == 3 then do
  117.          mail = 1
  118.          call FOLLOW_UP
  119.          end
  120.     otherwise call LEAVING
  121. end
  122.  
  123. /* main loop to assemble news */
  124. address command 'join t:NEWSHeader.temp t:NEWSbody.temp AS t:NEWSedit.temp'
  125. glue = 'join t:NEWSedit.temp '||sigfile||' AS t:NEWSfinished.temp'
  126. rtresult = 2
  127. Do forever
  128.    if rtresult == 2 then do
  129.     address command editor||' t:NEWSedit.temp '||editorflags
  130.          end
  131.    call rtezrequest('Time to check before sending...Choose an action',,
  132.     '_Send|_Edit|_List|_Abort',,'rtez_defaultresponse = 1 ' screentag)
  133.  
  134.    if rtresult == 3 then do
  135.       address command glue
  136.       address command 'sys:utilities/multiview t:NEWSfinished.temp pubscreen '||SCREENNAME 
  137.     end
  138.    if rtresult == 2 then iterate
  139.    if rtresult == 1 then leave
  140.    if rtresult == 0 then call LEAVING
  141. end
  142.     address command glue
  143.  
  144.     if mail then do
  145.     address command postmail||' <t:NEWSfinished.temp'
  146.     call LEAVING 
  147.     exit 0
  148.     end 
  149.  
  150.     address command postnews||' <t:NEWSfinished.temp'
  151.     call LEAVING 
  152.     exit 0
  153.  
  154. /* functions begin here */
  155.  
  156. WRITE:
  157.         call MESSAGE
  158.     if open('outfile', 't:NEWSitem.temp', 'R') then
  159.  
  160.     do until nextjunk == '<DT> Newsgroups:'
  161.     nextjunk = readln('outfile')
  162.     if LEFT(nextjunk,'16') = '<TITLE>Newsgroup' then leave
  163.     end
  164.         
  165.     if LEFT(nextjunk,'16') = '<TITLE>Newsgroup' then do
  166.     parse value nextjunk with '<TITLE>Newsgroup ' NEWSgroups ','
  167.     end
  168.     
  169.     else do
  170.     NEWSgroups = readln('outfile')
  171.         call NEWSGROUPS
  172.     end
  173.  
  174. /* Get Subject from user */
  175.  
  176.     buffer = rtgetstring("", , "Enter subject:", , screentag)
  177.     if buffer == "" then do
  178.           call rtezrequest("You entered nothing!", "Bye",, screentag)
  179.           call LEAVING
  180.           end
  181.     else
  182.       NEWSsubject = strip(buffer)
  183.  
  184.     open('Headfile', 't:NEWSHeader.temp', 'W')
  185.  
  186.         From = 'From: '||from
  187.     writeln('Headfile',From)    
  188.     
  189.         ngroup = 'Newsgroups: '||NEWSgroups
  190.     writeln('Headfile',ngroup)
  191.  
  192.         subject = 'Subject: '||NEWSsubject
  193.     writeln('Headfile',subject)
  194.  
  195. /* add blank.line at end of header */
  196.     
  197.     writeln('Headfile','')
  198.     close('Headfile')
  199.  
  200. /* opening address */
  201.  
  202.     open('infile', 't:NEWSbody.temp', 'W')    
  203.         writeln('infile',greeting)
  204.     close('infile')
  205. return
  206.  
  207. FOLLOW_UP:
  208.  
  209. /* fetch news item from AmigaMosaic */
  210.  
  211.     call URL
  212.  
  213.     call MESSAGE
  214.  
  215.     
  216. /* parse NEWSitem for writer's address */
  217.     if open('outfile', 't:NEWSitem.temp', 'R') then
  218.         NEWSaddress = readln('outfile')
  219.         Junk = left(NEWSaddress,'9')
  220.                     
  221.     if  junk ~= '<ADDRESS>' then
  222.         say 'Unable to recognise address line'
  223.     else
  224.         NEWSaddress = delstr(NEWSaddress,'1','9')
  225.         NEWSaddress = strip(NEWSaddress)
  226.  
  227. /* extract realname & email address */
  228.     marker = RIGHT(NEWSaddress,1)
  229.         SELECT
  230.     when marker = '>' then DO
  231.         place = INDEX(NEWSaddress,'<')
  232.         REALNAME = DELSTR(NEWSaddress,place)
  233.                 MAILADDR = DELSTR(NEWSaddress,1,place)
  234.         MAILADDR = COMPRESS(MAILADDR,'<> ')
  235.         end
  236.     when marker = ')' then DO
  237.         place = INDEX(NEWSaddress,'(')
  238.         REALNAME = DELSTR(NEWSaddress,1,place)
  239.         REALNAME = COMPRESS(REALNAME,'()')
  240.                 MAILADDR = COMPRESS(DELSTR(NEWSaddress,place))
  241.         end
  242.     otherwise REALNAME = NEWSaddress
  243.         END            
  244. /* skip next line of NEWSitem */
  245.     junk = readln('outfile')
  246.  
  247. /* Get subject from NEWSitem */
  248.     NEWSsubject = readln('outfile')
  249.     junk = left(NEWSsubject,'7')
  250.         if  junk ~= '<TITLE>' then
  251.             say 'Unable to recognise subject line'
  252.         else
  253.             parse value NEWSsubject with '<TITLE> ' NEWSsubject '</TITLE>'
  254. /* skip the next few lines of NEWSitem */
  255.  
  256.     do until nextjunk == '<DT> Newsgroups:'
  257.         nextjunk = readln('outfile')
  258.     end
  259.  
  260.     NEWSgroups = readln('outfile')
  261.     
  262.     CALL NEWSGROUPS
  263.  
  264. /* pull out references */
  265.  
  266.     nextjunk = readln('outfile')
  267.     if nextjunk == '<DT> References:' then do
  268.                 NEWSrefs = ''
  269.                 remain = readln('outfile')
  270.         junk = left(remain,'13')
  271.         if  junk ~= '<DD> <A HREF=' then
  272.             do
  273.             say 'Unable to recognise NEWSrefs line'
  274.             end
  275.         else     
  276.             do until remain = ''
  277.             parse value remain with '">' junk '</A>' remain
  278.                         NEWSrefs = NEWSrefs||junk
  279.                       end
  280.             
  281.             NEWSrefs = NEWSrefs||' '||NEWSfrom
  282.         end
  283.     else NEWSrefs = NEWSfrom
  284.         
  285.     do until left(nextjunk,'5') = '<PRE>' 
  286.            nextjunk = readln('outfile')
  287.     end
  288.  
  289.     
  290. call HEADER
  291.  
  292. /* body of letter */
  293.  
  294.     open('infile', 't:NEWSbody.temp', 'W')    
  295.  
  296.  
  297. /* opening address */
  298.  
  299.     greeting = 'In article '||NEWSfrom||' '||realname||' wrote:'||'0a'x
  300.     writeln('infile',greeting)
  301.  
  302.     NEWSbody = nextjunk
  303.     NEWSbody = delstr(NEWSbody,'1','5')
  304.  
  305.     do until NEWSbody == '</PRE>'
  306.         do until junk = ''
  307.                 parse value NEWSbody with 1 leader '<A HREF="' junk '">' ref2 '</A>' remain
  308.         NEWSbody = leader||ref2||remain
  309.                 end
  310.         NEWSbody = '>'||NEWSbody
  311.         writeln('infile',NEWSbody)
  312.         NEWSbody = readln('outfile')
  313.     end
  314.  
  315.     close('infile')
  316.     close('outfile')
  317. return
  318.  
  319. URL: 
  320. 'get url'
  321.     NEWSfrom = result
  322.  
  323.     /* prepare NEWSfrom line */
  324.  
  325.     junk = left(NEWSfrom,'5')
  326.  
  327.     junk = translate(junk)
  328.      if  junk ~= 'NEWS:' then do
  329.         say 'Unable to recognise NEWSfrom line'
  330.                 end
  331.     else 
  332.         NEWSfrom = delstr(NEWSfrom,'1','5')
  333.         NEWSfrom = strip(NEWSfrom,'L','<')
  334.         NEWSfrom = '<'||NEWSfrom||'>'
  335. return 
  336.  
  337. MESSAGE:
  338. 'fetch source'
  339.     NewsDoc = result
  340.  
  341.         open('infile', 't:NEWSitem.temp', 'W')
  342.             writech( 'infile', NewsDoc )
  343.         close('infile')
  344. return
  345.  
  346. HEADER:
  347. /* build news header */
  348.     open('Headfile', 't:NEWSHeader.temp', 'W')
  349.  
  350.         From = 'From: '||from
  351.     writeln('Headfile',From)    
  352.     
  353.     SELECT
  354.         when mail then do
  355.             To = 'To: '||MAILADDR
  356.             writeln('Headfile',To)
  357.         end
  358.         otherwise do
  359.             ngroup = 'Newsgroups: '||NEWSgroups
  360.             writeln('Headfile',ngroup)
  361.         end
  362.     END
  363.     
  364.         ToRe = left(NEWSsubject,'2')
  365.         ToRe = TRANSLATE(ToRe)
  366.         if ToRE ~= 'RE' then 
  367.             subject = 'Subject: '||'Re:'||NEWSsubject
  368.         
  369.         else 
  370.             subject = 'Subject: '||NEWSsubject
  371.     writeln('Headfile',subject)
  372.     
  373.     IF ~mail then do
  374.     if NEWSrefs ~= '' then do
  375.         NEWSrefs = 'References: '||NEWSrefs
  376.         writeln('Headfile',NEWSrefs)
  377.         end
  378.         end
  379. /* add blank line at end of header */
  380.     
  381.     writeln('Headfile','')
  382.     
  383.     close('Headfile')
  384. return
  385.  
  386. NEWSGROUPS:
  387.     junk = left(NEWSgroups,'13')
  388.         if  junk ~= '<DD> <A HREF=' then
  389.             do
  390.             say 'Unable to recognise NEWSgroups line'
  391.             end
  392.         else     do 
  393.             nextjunk = ''                     
  394.             do until NEWSgroups = ''
  395.             parse value NEWSgroups with '">' junk '</A>' NEWSgroups
  396.                         nextjunk = nextjunk||junk
  397.                       end
  398.             end
  399.     NEWSgroups = compress(nextjunk)
  400. return
  401.  
  402. LEAVING:
  403.     if exists('t:NEWSitem.temp') then
  404.         address command 'delete t:NEWSitem.temp'
  405.     
  406.     if exists('t:NEWSHeader.temp') then
  407.         address command 'delete t:NEWSHeader.temp'
  408.  
  409.     if exists('t:NEWSbody.temp') then
  410.         address command 'delete t:NEWSbody.temp'
  411.  
  412.     if exists('t:NEWSedit.temp') then
  413.         address command 'delete t:NEWSedit.temp'
  414.     
  415.     if exists('t:NEWSFinished.temp') then
  416.         address command 'delete t:NEWSFinished.temp'
  417.  
  418. /* if we used Workbench as our public screen this will return Amosaic */
  419. /* to the front, or has no effect if Amosaic is already in front      */
  420.  
  421. 'screen front'
  422. exit 0
  423.  
  424.